<?php
/**
* @software         [JiJinCMS]
* @author           [上海集锦信息科技有限公司]
* @website          [http://www.jijinweb.com]
* @email            [sunny@jijinweb.com]
**/
namespace app\admin\controller;
use think\facade\View;
use think\facade\Request;
class Config extends \app\admin\controller\Admin{
    public function __construct(\think\App $app) {
        parent::__construct($app);
    }
    public function index(){
        if(request()->isPost()){
            $conarr=["setting","email","mobile","upload_img","upload_video","upload_file","login"];
            foreach($conarr as $conf){                 
                $settingstr="<?php \n return ".var_export($_POST[$conf],true).";";//配置文件str
                if(get_magic_quotes_gpc()){   //如果get_magic_quotes_gpc()是打开的
                    $settingstr=stripslashes($settingstr);//将字符串进行处理    
                }                  
                $setting_path=config_path()."extra/".$conf.".php";//配置文件路径
                file_put_contents($setting_path,$settingstr);//保存到配置文件里
            }
            //
            $this->UserLogModel->add("update","网站设置","-");     
            $this->success("保存成功");            
        }
        return View::fetch();
    }
    //测试发邮件
    public function testMail(){
        if(request()->isPost()){
            $data=$this->request->param();
            $validate = \think\facade\Validate::rule(['to'=>'require','title'=>'require','content'=>'require'])->message([
                "to.require"=>"请填写收件人",
                "title.require"=>"请填写标题",
                "content.require"=>"请填写内容",
            ]);
            if (!$validate->check(Request::param())) {
                $this->error($validate->getError());
            }
            $phpMailer=new \app\common\PhpMail\PhpMail();
            if($phpMailer->sendMail($data["to"], $data["title"], $data["content"])){
                $this->success("发送成功");
            }else{
                $this->error($phpMailer->error);
            }
        }else{
            View::assign("pagetitle","测试邮件");
            return View::fetch();
        }
    }
     //测试发短信
    public function testMobile(){
        if(request()->isPost()){
            $data=$this->request->param();
            $validate = \think\facade\Validate::rule(['mobile'=>'require|mobile'])->message([
                "mobile.require"=>"请填写手机",
                "mobile.mobile"=>"手机号码不正确",
            ]);
            if (!$validate->check($data)) {
                $this->error($validate->getError());
            }
            $MobileVerify=new \app\common\MobileVerify\MobileVerify();
            $result=$MobileVerify->send_code($data['mobile']);
            if($result){
                $this->success("短信发送成功");
            }else{
                $this->error($code->error);
            }            
        }else{
            View::assign("pagetitle","测试短信");
            return View::fetch();
        }
    }
}